class Solution {
public:
    vector<int> canSeePersonsCount(vector<int>& heights) {
        vector<int> ans(heights.size(), 0);
        deque<int> que;
        for (int i = heights.size() - 1; i >= 0; i--)
        {
            int num = 0;
            while (!que.empty() && heights[i] > que.back())
            {
                num += 1;
                que.pop_back();
            }
            que.push_back(heights[i]);
            ans[i] = num + (que.size() > 1);
        }
        return ans;
    }
};